package com.seveneight.baijiesteward.ui.user.model;

import android.content.Context;

import com.alibaba.fastjson.JSON;
import com.seveneight.baijiesteward.bean.AnyBean;
import com.seveneight.baijiesteward.bean.BaseEntity;
import com.seveneight.baijiesteward.bean.RankBean;
import com.seveneight.baijiesteward.http.BaseModel;
import com.seveneight.baijiesteward.http.BaseObserver;
import com.seveneight.baijiesteward.http.MyCallBack;
import com.seveneight.baijiesteward.http.RetrofitFactory;
import com.seveneight.baijiesteward.ui.user.contract.GetRankListContract;

import java.util.List;

import okhttp3.RequestBody;

/**
 * Created by user1 on 2018/3/24.
 */

public class GetRankListModel extends BaseModel implements GetRankListContract.GetRankListModel {
    @Override
    public void getRankList(Context context, RequestBody body, MyCallBack<List<RankBean>> myCallBack) {
        RetrofitFactory.getInstence().API().getRankList(body).
                compose(this.<BaseEntity<AnyBean>>setThread())
                .subscribe(new BaseObserver<AnyBean>(context) {
                    @Override
                    protected void onSuccees(BaseEntity<AnyBean> t) throws Exception {
                        if (t.getData().getRankList() != null) {
                            List<RankBean> data = JSON.parseArray(t.getData().getRankList(), RankBean.class);
                            myCallBack.onSuccess(data);
                        }
                    }

                    @Override
                    protected void onFailure(Throwable e, boolean isNetWorkError) throws Exception {

                    }
                });
    }
}
